# python里的 function 以及常用函数
import math
import new_function_star


# 试着把另一个文件的函数作为模块导入
new_function_star.let_us_stars()

# 不带参数值的 return 语句返回 None
# isinstance 检测数据类型

def my_asd(x):
    if not isinstance(x, (int, float)):
        raise TypeError('参数错误')
    if x >= 0:
        return x
    else:
        return -x


print(my_asd(2323))
#  类型不对会报错
# print(my_asd("123"))


def division(num1, num2):
    # 求商与余数
    a = num1 % num2
    b = (num1 - a) / num2
    return b, a


answer_a, answer_b = division(9, 4)
print(answer_a, answer_b)
print(division(9, 4))
# num1, num2 = division(9, 4)
# tuple1 = division(9, 4)
#
# print(num1, num2)
# print(tuple1)




def move(x, y, step, angle=0):
    nx = x + step * math.cos(angle)
    ny = y + step * math.sin(angle)
    return nx, ny


# 可以看出这里的函数返回值用逗号隔开 实际是创建了个元组返回的
r = move(100, 100, 60, math.pi / 6)
print('位移后', 'x,y:', r)


"""
和PHP不一样的一点 函数作用域
"""


def add_end():
    L.append('END')


L = ["HERE"]
add_end()
add_end()
add_end()
# print(L)    # ['HERE', 'END', 'END', 'END']


def add_end_new(L_2=None):
    if L_2 is None:
        L_2 = []
    L_2.append('end')
    return L_2


print(add_end_new())
print(add_end_new())
print(add_end_new())
print(add_end_new(L))

# 善用切片 一行代码打印100以内7的倍数
for i in range(1, 100)[6::7]:
    print(i)


#
